<?php
  require(dirname(__FILE__).'/global.php');
  
  $email = $_POST['useremail'];
  if(!isset($email))
  {
      $smarty->assign('action','find'); 
      $smarty->display('findpassword.html');
      unset($_SESSION['post']);
  }
  else
  {
      if(isset($_SESSION['post']))
      {
          header("Location: findpassword.php");
      }
      $_SESSION['post'] = true;
      $sql = "select UserEmail from talking_user where UserEmail = '$email'";
      $users = $db->query($sql);
      if(count($users)==0)
      {
          echo '邮箱未注册！';
          exit();
      }
      //发送邮件
      require(ROOT.'/include/email.class.php');
      $smtpserver = $xml->getElementValue('SmtpServer');//SMTP服务器
      $smtpserverport = $xml->getElementValue('SmtpPort');;//SMTP服务器端口
      $smtpusermail = "jt_success@163.com";//SMTP服务器的用户邮箱
      $smtpemailto = "jt_success@sina.com";//发送给谁
      $smtpuser = "jt_success";//SMTP服务器的用户帐号
      $smtppass = "taotao112277";//SMTP服务器的用户密码
      $mailsubject = "PHP100测试邮件系统";//邮件主题
      $mailbody = "<h1> 这是一个测试程序 PHP100.com </h1>";//邮件内容
      $mailtype = "HTML";//邮件格式（HTML/TXT）,TXT为文本邮件
      $smtp = new Smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);
      $smtp->debug = false;
      $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
      
      $url = explode('@',$email);
      $url = 'http://mail.'.$url[1];
      $smarty->assign('emailURL',$url);
      $smarty->assign('action','success'); 
      $smarty->display('findpassword.html');                                 
  }                                    
?>
